<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
  <title>Ubiquity Web Search Commands for Japanese, nora</title>
</head>
<body>
<p>This xhtml source contains commands for searching the Web.  Its
corresponding feed is <a href="ubiquity-commands-ja-nora-all.html">here</a>.</p>


<div id="jwikipedia" style="display: none;">
<b>${query}</b>に該当するWikipediaの記事:

{for article in results}
  <div style="clear: both;border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:2px 0px 0px 0px;padding:0px;">
    <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;font-size:90%;">
        <a href="${article.title|wikilink}" accesskey="${article.key}">
        <span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${article.key}</span><b>${article.title}</b>
        </a>
    </div>
    <div style="margin-left: 10px; font-size: 80%;" wikiarticle="${article.title}">
      <i>項目の詳細を取得中...</i>
    </div>
    <div style="clear:both;"> </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
<div style="font-size:70%;clear:both;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="jamazon" style="display: none;">
    <style>
        .price span{color:#FF9999;}
        .timeLeft{color:#99FF99;font-weight:bold;}
        .deliveryDate{font-weight:bold;}
    </style>
    検索語:<b>${query}</b>
    <div class="items" id="items">
        {for item in items}
            <div class="item" id="item${item.key}" style="clear: both; padding: 0px; margin: 2px 0px 0px 0px;border:1px solid #777777; -moz-border-radius:4px;background:#333333;">
                <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;font-size:85%;">
                    <a href="${item.url}" accesskey="${item.key}">
                    <span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b>
                    </a>
                </div>
                <div style="float:left;">
                    {if item.image}
                        <img
                            src="${item.image.src}"
                            style="float: left; margin: 2px 4px 2px 2px; height: ${item.image.height}px; width: ${item.image.width}px;"
                            />
                    {/if}
                </div>
                <div style="font-size:70%;">
                    {if item.binding}
                        ${item.binding} 
                    {/if}
                    {if item.price}
                        <br /><span class="price" style="margin-right:15px;font-weight:bold;">${item.price.retail}</span>
                        <span class="price" style="font-size:85%;">${item.price.used}</span>
                    {/if}
                    <span style="font-size:85%;">
                        {if item.track}
                            <br />${item.track}
                        {/if}
                        {if item.sss}
                            <br />${item.sss}
                        {/if}
                    </span>
                </div>
                <div style="clear:both;"> </div>
            </div>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:2px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
        <div class="navigation" style="font-size:70%;float:right;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>


<div id="alc" style="display:none;">
    <b>${query}</b>に該当するALCの記事:
    <div style="clear:both;">
        <u>${title}</u>
        <small>
        <br />
        ${detail}
        </small>
    </div>
</div>

<div id="alcs" style="display:none;">
    <b>${query}</b>に該当するALCの見出し一覧:
    <div style="clear:both;">
        <small>
        <br />
        ${detail}
        </small>
    </div>
</div>

<div id="2ch" style="display: none;">
<b>${query}</b>で2chのスレッドタイトルを検索:
<br/><br/>
{for item in items}
  <div style="clear: both;font-size:90%;">
    <b>${item.key} <a href="${item.url}" accesskey="${item.key}">${item.title}</a></b>
    <br/>
    <div style="margin-left: 20px; font-size: 90%;">
      ${item.description}
    </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
<div style="font-size:70%;clear:both;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="kakaku" style="display: none;">
<b>${query}</b>でkakaku.comを検索:
<br/>
{for item in items}
  <div style="clear:both;font-size:90%;border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:1px 0px 0px 0px;padding:0px;">
    <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
        <a href="${item.url}" accesskey="${item.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b></a>
    </div>
    <div>
        {if item.imgsrc}
            <img
                src="${item.imgsrc}"
                style="float: left;margin: 1px 2px 1px 1px; width: 50px;"
                alt="${item.imgalt}"
            />
        {/if}
        <div style="margin-left: 20px; font-size: 85%;">
          ${item.description}
        </div>
        <div style="clear:left;"> </div>
    </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
<div style="font-size:30%;"> <br/></div>
{for category in categories}
    <div style="clear:both;font-size:80%;border:1px solid #666666; -moz-border-radius:3px;background:#444444;margin:0px;padding:0px;">
        <A href="${category.url}" accesskey="${category.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${category.key}</span></A> ${category.html}
    </div>
{/for}
<div style="font-size:70%;clear:both;margin:7px 0px 0px 0px;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="goodict" style="display: none;">
<b>${query}</b>でgoo辞書を検索:
<br/><br/>
{for item in items}
  <div style="clear: both;font-size:90%;">
    <b>${item.key} <a href="${item.url}" accesskey="${item.key}">${item.entry}</a></b>
    <br/>
    <div style="margin-left: 20px; font-size: 90%;">
      ${item.meanings}
      <br/>
      <A href="${item.dictionaryUrl}">${item.dictionary}</A>
    </div>
    <div style="font-size:60%;clear:both;"> <br/></div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
    <div style="font-size:30%;clear:both;"> <br/></div>
    <div style="font-size:70%;clear:both;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="sagawa" style="display:none;">
    <b>${query}</b> に該当するSagawaの荷物一覧:
    <div style="clear:both;">
        <br />
        ${detail}
    </div>
</div>

<div id="kuronekoyamato" style="display:none;">
    <b>${query}</b> に該当するヤマト運輸の荷物一覧:
    <div style="clear:both;">
        <br />
        ${detail}
    </div>
</div>

<div id="yuupack" style="display:none;">
    <b>${query}</b> に該当するゆうパックの荷物:
    <div style="clear:both;">
        <br />
        ${detail}
    </div>
</div>

<div id="kakitome" style="display:none;">
    <b>${query}</b> に該当する書留の記録:
    <div style="clear:both;">
        <br />
        ${detail}
    </div>
</div>

<div id="kotobank" style="display: none;">
<b>${query}</b>でKotobankを検索:
<br/><br/>
{for item in items}
  <div style="clear: both;font-size:90%;">
    <b>${item.title}</b>
    <br/>
    <div style="margin-left: 20px; font-size: 90%;">
      ${item.doc}
      <br/>
      <A href="${item.dictionaryUrl}">${item.dictionary}</A>
    </div>
    <div style="font-size:60%;clear:both;"> <br/></div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
    <div style="font-size:30%;clear:both;"> <br/></div>
</div>


<div id="yahoo-news" style="display: none;">
<b>${query}</b>で Yahoo! news を検索:
{for item in items}
  <div style="font-size:90%;">
    <div style="border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:2px 0px 0px 0px;padding:0px;">
        <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
            <A href="${item.url}" accesskey="${item.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b></A>
        </div>
        {if item.photo}
            <div style="float:right;margin:1px 1px 1px 3px;">${item.photo}</div>
        {/if}
        <div style="margin-left: 10px; font-size: 85%;">
            ${item.description}
        </div>
        <div style="margin-left:10px;font-size:70%;">
            ${item.date}${item.typeImg}
        </div>
        <div style="clear:both;"> </div>
    </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
    <div style="font-size:70%;clear:both;margin-top:7px;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="gooweather" style="display : none;">
<div style="font-size:80%">郵便番号<b>${query}</b>でgoo天気を検索:</div>
  <div style="clear: both;font-size:90%;">
    {if item.title}
        <div style="border:1px solid #888888; -moz-border-radius:4px;background:#777777;margin:0px;padding:0px;">
            <b>${item.title}</b> ${item.today}
        </div>
    {/if}
    {if item.todayTable}
        <div>
          ${item.todayTable}
          ${item.tomorrowTable}
        </div>
    {elseif item.weeklyTable}
        <div>
          ${item.weeklyTitle}
          ${item.weeklyTable}
        </div>
    {else}
        <P>検索条件に該当する地域はありませんでした。</P>
    {/if}
  </div>
</div>



<div id="google-news" style="display: none;">
<b>${query}</b>で Google news を検索:
<span style="font-size:xx-small;">${resultsstats}</span>
{for item in items}
  <div style="font-size:90%;">
    <div style="border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:4px 0px 0px 0px;padding:0px;">
        <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
            <A href="${item.url}" accesskey="${item.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b></A>
            <span style="font-size:70%;">${item.sourcemedia}</span>
        </div>
        {if item.photo}
        <div style="float:right;margin:1px 1px 1px 4px; font-size: 70%;">${item.photo}</div>
        {/if}
        <div style="margin-left: 4px; font-size: 85%;">
          ${item.description}
        </div>
        <div style="clear:both;"> </div>
    </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
    <div style="font-size:70%;clear:both;margin:7px 0px 0px 0px;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>


<div id="yahoo-auctions" style="display: none;">
<b>${query}</b>で Yahoo! Auctions を検索: ${resultsnum}件
    <div class="items" id="items">
        {for item in items}
            <div class="item" style="clear: both;border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:2px 0px 0px 0px;padding:0px;">
                <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;font-size:90%;">
                    <a href="${item.url}" accesskey="${item.key}">
                        <span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b>
                    </a>
                </div>
                <div class="itemview">
                    <div style="float:left;margin:1px 1px 1px 1px;" id="${item.auctionID}" class="thumbnail" imgsrc="${item.img}">
                        
                    </div>
                    <div style="font-size:75%;" class="sub">
                        現在の価格:<b>${item.price}</b> 入札件数:${item.bids} 終了日時:${item.endtime}{if item.bidorbuy} 希望落札価格:${item.bidorbuy}{/if}
                        出品者:<a href="${item.seller.itemlist}">${item.seller.id}</a>(<a href="${item.seller.rating}">評価</a>)
                        <span class="option">
                            {for opt in item.option}
                                <img src="${opt}" height="12" />
                            {/for}
                        </span>
                        <span style="margin:0px 0px 0px 0px;" id="desc_${item.auctionID}" class="description">
                          <i>説明を取得中...</i>
                        </span>
                    </div>
                </div>
                <div style="clear:both;"> </div>
            </div>
        {forelse}
            <b>該当項目が見つかりませんでした</b>
        {/for}
    </div>
    <div class="bottom" style="position:absolute;bottom:11px;right:0px;height:13px;width:100%;padding:0px;margin:0px;background:rgba(40,40,40,0.7);">
        <div class="note" style="font-size:70%;clear:both;float:left;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
        <div class="navigation" style="font-size:70%;float:right;">
            <a id="prev" accesskey="8"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">&lt;Prev(<u>8</u>)</span></a>
            Page <span id="page">${page}</span>
            <a id="next" accesskey="9"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 1px 2px; max-width:30px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#000000;box-shadow:2px 2px 2px black;">Next(<u>9</u>)&gt;</span></a>
        </div>
    </div>
</div>


<script class="commands"><![CDATA[

//
// jwikipedia search
// ja.wikipedia.org
//


CmdUtils.CreateCommand({
  //
  // about Original Source Code (Wikipedia search command)
  //
  //homepage: "http://theunfocused.net/moz/ubiquity/verbs/",
  //author: {name: "Blair McBride", email: "blair@theunfocused.net"},
  //contributors: ["Viktor Pyatkovka"],
  //license: "MPL",
  //
  name: "jwikipedia",
  synonyms: ["lookup"],
  takes: {search: noun_arb_text},
  homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
  author: {name: "hokunarin", email: "hokunarin@gmail.com"},
  license: "MPL",
  
  icon: "http://ja.wikipedia.org/favicon.ico",
  description: "Wikipedia日本語版を検索します",
  preview: function(previewBlock, directObject) {
    var apiUrl = "http://ja.wikipedia.org/w/api.php";

    var searchText = jQuery.trim(directObject.text);
    if(searchText.length < 1) {
      var previewStr = "Wikipedia日本語版検索";
      previewBlock.innerHTML = previewStr;
      return;
    }

    var previewTemplate = "<b>${query}</b> をWikipedia日本語版で検索します...";
    var previewData = {query: searchText};
    previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);

    var apiParams = {
      format: "json",
      action: "query",
      list: "search",
      srlimit: 5,
      srwhat: "text",
      srsearch: searchText
    };

    CmdUtils.previewAjax(previewBlock, {
      type: "GET",
      url: apiUrl,
      data: apiParams,
      datatype: "string",
      error: function() {
        previewBlock.innerHTML = "Error searching Wikipedia";
      },
      success: function(searchResponse) {
        searchResponse = Utils.decodeJson(searchResponse);

        if(!("query" in searchResponse && "search" in searchResponse.query)) {
          previewBlock.innerHTML = "Error searching Wikipedia";
          return;
        }

        function generateWikipediaLink(title) {
          var wikipediaUrl = "http://ja.wikipedia.org/wiki/";
          return wikipediaUrl + title.replace(/ /g, "_");
        }

	//for access keys
        for(var i=0;i<searchResponse.query.search.length;i++){
          searchResponse.query.search[i].key = i+1;
        }

        previewData = {
          query: searchText,
          results: searchResponse.query.search,
          _MODIFIERS: {wikilink: generateWikipediaLink}
        };

        previewBlock.innerHTML = CmdUtils.renderTemplate(
          jQuery("#jwikipedia", feed.dom).html(),
          previewData);

        jQuery(previewBlock).find("div[wikiarticle]").each(function() {
          var article = jQuery(this).attr("wikiarticle");
          fetchWikipediaArticle(this, article);
        });

      }
    });
  },
  execute: function(directObject) {
    var searchUrl = "http://ja.wikipedia.org/wiki/Special:Search";
    var searchParams = {search: directObject.text};
    Utils.openUrlInBrowser(searchUrl + Utils.paramsToString(searchParams));
  }
});

function fetchWikipediaArticle(previewBlock, articleTitle) {
  /* TODO
   - apply CSS max-height & overflow-y to summary container
  */
  var apiUrl = "http://ja.wikipedia.org/w/api.php";
  var apiParams = {
    format: "json",
    action: "parse",
    page: articleTitle
  };

  CmdUtils.previewAjax(previewBlock, {
    type: "GET",
    url: apiUrl,
    data: apiParams,
    datatype: "string",
    error: function() {
      previewBlock.innerHTML = "<i>概要の取得失敗</i>";
    },
    success: function(responseData) {
      responseData = Utils.decodeJson(responseData);

      var tempElement = previewBlock.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml", "div");
      tempElement.innerHTML = responseData.parse.text["*"];

      var articleSummary = jQuery(tempElement).find('p').eq(0).text();

      articleSummary = articleSummary.replace(/\[([^\]]+)\]/g,"");

      var articleImageSrc = jQuery(tempElement).find(".infobox img").attr("src") ||
      jQuery(tempElement).find(".thumbimage").attr("src");

      var previewTemplate = "<img src=\"${img}\" style=\"float: left; max-width: 80px; max-height: 80px; background-color: white; margin: 1px 1px 1px 1px;\" />" +
      "<span class=\"wikisummary\">${summary}</span>";

      var previewData = {
        img: articleImageSrc,
        summary: articleSummary
      };

      previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
    }
  });
}


//
// jamazon search
// www.amazon.co.jp
//

CmdUtils.CreateCommand({
    name: "jamazon",
    takes: {search: noun_arb_text},
    icon: "http://www.amazon.co.jp/favicon.ico",
    description: "<a href=\"http://www.amazon.co.jp\">Amazon.co.jp</a> 内を検索します",
    homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
    author: {name: "hokunarin", email: "hokunarin@gmail.com"},
    license: "MPL",
    
    execute: function(directObject, modifier){
        
        var urlString = "http://www.amazon.co.jp/s/ref=nb_ss_gw?__mk_ja_JP=%83J%83%5E%83J%83i&url=search-alias%3Daps&field-keywords={QUERY}";
        
        var encodedQuery = escape( Utils.convertFromUnicode("Shift-JIS", directObject.text) );
        
        urlString = urlString.replace(/%s|{QUERY}/g, encodedQuery);
        Utils.openUrlInBrowser(urlString); 
        
    },
    
    preview: function(previewBlock, directObject) {
        
        if(!directObject.text || directObject.text.length < 1) {
            previewBlock.innerHTML = "Amazon.co.jp 内の主な商品を検索します";
            return;
        }
        
        previewBlock.innerHTML = "<b>" + directObject.summary + "</b> を Amazon.co.jp 内で検索";
        jQuery(previewBlock).append('<div style="position:absolute;top:40%;left:40%;width:100px;height:50px;" id="progressimage"><img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" /></div>').find("#progressimage").hide().fadeIn(2000);
        
        var apiUrl = "http://www.amazon.co.jp/s/ref=nb_ss_gw?__mk_ja_JP=%83J%83%5E%83J%83i&url=search-alias%3Daps&field-keywords={QUERY}";
        var encodedQuery = escape( Utils.convertFromUnicode("Shift-JIS", directObject.text) );
        apiUrl = apiUrl.replace(/%s|{QUERY}/g, encodedQuery);
        
        var ubiquityVersion = Application.prefs.get("extensions.ubiquity.lastversion").value;
        
        var lastCursor = 0;
        var currentPage = 1;
        var prevUrl = "";
        var currentUrl = "";
        var nextUrl = "";
        
        renderItems(0);
        
        function renderItems(pageDiff){
            
            jQuery("#items", previewBlock).replaceWith('<div style="position:absolute;top:40%;left:40%;width:100px;height:50px;" id="progressimage"><img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" /></div>').find("#progressimage").hide().fadeIn(2000);
            
            var itemsPerQuery = 16;
            var itemsPerPage = 5;
            //var currentPage = eval(jQuery("#page", previewBlock).text());
            
            if(currentPage>0){
                currentPage = currentPage + pageDiff;
            }else{
                currentPage = 1;
            }
            
            var queryUrlFirst = "";
            var queryUrlSecond = "";
            var startCursor = 1;
            
            if( pageDiff == 0 ){
                queryUrlFirst = apiUrl;
                queryUrlSecond = null;
                startCursor = 1;
            }else if( pageDiff > 0 ){
                if(lastCursor + itemsPerPage <= itemsPerQuery){
                    queryUrlFirst = currentUrl;
                    queryUrlSecond = null;
                    startCursor = lastCursor + 1;
                }else if(lastCursor == itemsPerQuery){
                    queryUrlFirst = nextUrl;
                    queryUrlSecond = null;
                    startCursor = 1;
                }else{
                    queryUrlFirst = currentUrl;
                    queryUrlSecond = nextUrl;
                    startCursor = lastCursor + 1;
                }
            }else{
                if(lastCursor - itemsPerPage >= itemsPerPage){
                    queryUrlFirst = currentUrl;
                    queryUrlSecond = null;
                    startCursor = lastCursor - itemsPerPage * 2 + 1;
                }else if(lastCursor <= itemsPerPage){
                    queryUrlFirst = prevUrl;
                    queryUrlSecond = null;
                    startCursor = itemsPerQuery + lastCursor - itemsPerPage * 2 + 1;
                }else{
                    queryUrlFirst = prevUrl;
                    queryUrlSecond = currentUrl;
                    startCursor = itemsPerQuery + lastCursor - itemsPerPage * 2 + 1;
                }
            }
            
            var items = [];
            var i = 0;
            
            /*
            var responseDataFirst = null;
            var responseDataSecond = null;
            */
            
            //first query
            CmdUtils.previewAjax(previewBlock, {
                type: "GET",
                url: queryUrlFirst,
                dataType: "html",
                //async: false,
                error: function() {
                    previewBlock.innerHTML = "Error searching Amazon.";
                },
                success: function(responseData) {
                    
                    responseData = jQuery(responseData);
                    
                    var endCursor = (startCursor + itemsPerPage - 1 ) <= itemsPerQuery ? (startCursor + itemsPerPage - 1 ) : itemsPerQuery;
                    
                    //responseDataFirst = responseData.find(".result:not(.fkmrSeeMoreMessage)").slice( startCursor - 1, endCursor );
                    
                    
                    responseData.find(".result:not(.fkmrSeeMoreMessage)").slice( startCursor - 1, endCursor).each(function(){
                        
                        var newItem = getNewItem( jQuery(this) );
                        
                        newItem.key = ++i;
                        
                        items.push(newItem);
                    });
                    
                    
                    lastCursor = endCursor;
                    currentUrl = queryUrlFirst;
                    prevUrl = responseData.find(".pagnPrev a").attr("href");
                    nextUrl = responseData.find(".pagnNext a").attr("href");
                    
                    var itemsFirst = i;
                    
                    if(queryUrlSecond){
                        
                        //second query
                        CmdUtils.previewAjax(previewBlock, {
                            type: "GET",
                            url: queryUrlSecond,
                            dataType: "html",
                            //async: false,
                            error: function() {
                                previewBlock.innerHTML = "Error searching Amazon.";
                            },
                            success: function(responseData) {
                                
                                responseData = jQuery(responseData);
                                
                                //responseDataSecond = responseData.find(".result:not(.fkmrSeeMoreMessage)").slice( 0, itemsPerPage - itemsFirst );
                                
                                responseData.find(".result:not(.fkmrSeeMoreMessage)").slice( 0, itemsPerPage - itemsFirst).each(function(){
                                    
                                    var newItem = getNewItem( jQuery(this) );
                                    
                                    newItem.key = ++i;
                                    
                                    items.push(newItem);
                                });
                                
                                
                                lastCursor = itemsPerPage - itemsFirst;
                                currentUrl = queryUrlSecond;
                                prevUrl = responseData.find(".pagnPrev a").attr("href");
                                nextUrl = responseData.find(".pagnNext a").attr("href");
                                
                                endAjax();
                            },
                            complete: function(){
                                //endAjax();
                            }
                            
                        });
                    
                    }else{
                        endAjax();
                    }
                    
                    
                }
                
            });
            
            function endAjax(){
                
                /*
                if(responseDataFirst){
                    jQuery(responseDataFirst).each(function(){
                        var itemDetails = jQuery(this);
                        var newItem = getNewItem(itemDetails);
                        newItem.key = ++i;
                        items.push(newItem);
                    });
                }
                
                if(responseDataSecond){
                    jQuery(responseDataSecond).each(function(){
                        var itemDetails = jQuery(this);
                        var newItem = getNewItem(itemDetails);
                        newItem.key = ++i;
                        items.push(newItem);
                    });
                }
                */
                
                if(i < 5){
                    lastCursor = i;
                    nextUrl = null;
                }
                
                if( currentPage == 1 ){
                    prevUrl = null;
                }
                
                
                var previewData = {
                    query: directObject.text,
                    items: items,
                    page: currentPage
                };
                
                previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jamazon", feed.dom).html(), previewData);
                
                if(currentPage > 1){
                    jQuery("#prev", previewBlock).show();
                    jQuery("#prev", previewBlock).click(function(){
                        renderItems( -1 );
                        jQuery(this).unbind();
                    });
                }else{
                    jQuery("#prev", previewBlock).hide();
                }
                
                if( nextUrl != null ){
                    jQuery("#next", previewBlock).show();
                    jQuery("#next", previewBlock).click(function(evt){
                        renderItems( 1 );
                        jQuery(this).unbind();
                    });
                }else{
                    jQuery("#next", previewBlock).hide();
                }
                
                //for Ubiquity 0.1.x / 0.5  difference
                if (ubiquityVersion.indexOf("0.1.") > -1){
                    jQuery("#prev", previewBlock).attr({href:""});
                    jQuery("#next", previewBlock).attr({href:""});
                }else{
                    jQuery("#prev", previewBlock).removeAttr("href");
                    jQuery("#next", previewBlock).removeAttr("href");
                }
                
            }
            
            
            function getNewItem(itemDetails){
                
                var newItem = {
                    title: itemDetails.find(".productTitle a").text(),
                    url: itemDetails.find(".productTitle a").attr("href")
                };
                
                newItem.binding = "";
                itemDetails.find(".productTitle span").each(function(){
                    newItem.binding += jQuery(this).text();
                });
                
                var imgsrc = null;
                if(itemDetails.find(".productImage img").length > 0){
                    imgsrc = itemDetails.find(".productImage img").attr("src").replace(/SL160_AA115/g,"SL160_AA55");
                }else if(itemDetails.find(".productTitle img").length > 0){
                    imgsrc = itemDetails.find(".productTitle img").attr("src").replace(/SL160_AA115/g,"SL160_AA55");
                }
                newItem.image = {
                    src : imgsrc,
                    height : 55,
                    width : 55
                };
                
                newItem.price = {
                    retail : itemDetails.find(".newPrice").html(),
                    used : itemDetails.find(".usedPrice").html()
                };
                
                newItem.track = itemDetails.find(".fastTrack").html();
                
                newItem.sss = itemDetails.find(".sss").html();
                
                return newItem;
                
            }
            
        }
    
    }
});



var noun_type_alcentry = {
    _name : "alc entry",
    
    suggest : function(text, html){
        var suggestions = [];

        jQuery.ajax( {
            url: getAlcUrl(text),
            type : "GET",
            dataType: "HTML",
            async: false,
            cache: false,
            success: function(responseData){
                jQuery(responseData).find("#resultList li .midashi").slice(0,5).each(function(){
                    suggestions.push(CmdUtils.makeSugg(jQuery(this).text()));
                });
                if(suggestions.length==0)suggestions.push(CmdUtils.makeSugg(text));
            },
            error: function(text){
                suggestions.push(CmdUtils.makeSugg(text));
            }
        });
        
        return suggestions;
        
    }
};


CmdUtils.CreateCommand({
    name: "alc",
    description: "ALC 英辞郎 on the WEB",
    takes: {search: noun_arb_text},
    icon: "http://www.alc.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "ALC 英辞郎 on the WEB";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を ALC で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getAlcUrl(searchText),
          dataType: "html",
          cache: false,
          
          error: function() {
            previewBlock.innerHTML = "Error searching ALC.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            //var title = responseData.find(".midashi").text();
            //var detail = responseData.find("div .wordlink").text();
            var title = responseData.find("#resultList li:first .midashi").text();
            var detail = responseData.find("#resultList li:first DIV").html();
            
            var previewData = {
              query: searchText,
              title: title,
              detail: detail
            };
            
            //Utils.reportInfo(title + detail);
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
                                        jQuery("#alc", feed.dom).html(),
                                        previewData);
            
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( getAlcUrl(directObject.text) );
    }
});

CmdUtils.CreateCommand({
    name: "alc-suggest",
    description: "ALC 英辞郎 on the WEB",
    takes: {search: noun_type_alcentry},
    icon: "http://www.alc.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "ALC 英辞郎 on the WEB";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を ALC で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getAlcUrl(searchText),
          dataType: "html",
          cache: false,
          
          error: function() {
            previewBlock.innerHTML = "Error searching ALC.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var errorMsg = responseData.find("td:has(img[src='http://eowimg.alc.co.jp/content/img/bikkuri.gif'])").html();
            
            //var title = responseData.find(".midashi").text();
            //var detail = responseData.find("div .wordlink").text();
            var title = responseData.find("#resultList li:first .midashi").text();
            var detail = responseData.find("#resultList li:first DIV").html();
            
            var previewData = {
              query: searchText,
              title: title,
              detail: detail
            };
            
            //Utils.reportInfo(title + detail);
            
            if(errorMsg){
                previewBlock.innerHTML = errorMsg;
            }else{
                previewBlock.innerHTML = CmdUtils.renderTemplate(
                                            jQuery("#alc", feed.dom).html(),
                                            previewData);
            }
            
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( getAlcUrl(directObject.text) );
    }
});


CmdUtils.CreateCommand({
    name: "alc-list",
    description: "ALC 英辞郎 on the WEB 見出し語表示",
    takes: {search: noun_arb_text},
    icon: "http://www.alc.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "ALC 英辞郎 on the WEB 見出し語表示";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を ALC で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getAlcUrl(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching ALC.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var detail = "";
            responseData.find("#resultList li .midashi").each(function(){ detail = detail + jQuery(this).text() + "<br />" } );
            
            var previewData = {
              query: searchText,
              detail: detail
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#alcs", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( getAlcUrl(directObject.text) );
    }
});



function getAlcUrl(query){
    var url = "http://eow.alc.co.jp/{QUERY}/UTF-8/";
    url = url.replace(/%s|{QUERY}/g, jQuery.trim(query) );
    return url;
}



CmdUtils.CreateCommand({
    name: "2ch",
    description: "Find.2ch でスレッドタイトルを検索します",
    takes: {search: noun_arb_text},
    icon: "http://find.2ch.net/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "2ch のスレッドをタイトルで検索";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を 2ch のスレッドタイトルから検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        var searchUrl = get2chUrl(searchText);
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: searchUrl,
          dataType: "html",
          
          beforeSend: function(xhr){
            xhr.overrideMimeType("text/html;charset=EUC-JP");
          },
            
          error: function() {
            previewBlock.innerHTML = "Error searching Find.2ch.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var wrapper = responseData.find(".content_pane dl");
            
            var items = [];
            var count = wrapper.find("dt").length;
            
            count = ( count>=5 ) ? 5 : count;
            
            for (var i = 0; i < count; i++){
                
                
                wrapper.find(".r_sec_body:eq(" + i + ") a").each(function(){
                    var anchor = jQuery(this);
                    var anchorVal = anchor.attr("href");
                    
                    if(parseUri(anchorVal).host == ""){
                        anchor.attr("href", "http://find.2ch.net/" + anchorVal );
                    }
                    
                });
                
                /*
                wrapper.find(".r_sec_body:eq(" + i + ") a").attr("href", function(){
                    return addBaseUrl(this, "http://find.2ch.net/");
                });
                */
                var item = {
                    title : wrapper.find("dt:eq(" + i + ")").html(),
                    description : wrapper.find(".r_sec_body:eq(" + i + ")").html(),
                    key: i+1,
                    url: wrapper.find("dt:eq(" + i + ") a:first").attr("href")
                };
                
                items.push(item);
                
            }
            
            var previewData = {
                query: searchText,
                items: items
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#2ch", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( get2chUrl(directObject.text) );
    }
});

function get2chUrl(query){
    
    query = Utils.convertFromUnicode("Shift-JIS", query);
    query = escape(query);
    
    var url = "http://find.2ch.net/?BBS=ALL&TYPE=TITLE&IE=SJIS&OS&STR={QUERY}";
    url = url.replace(/%s|{QUERY}/g, query);
    return url;
}


CmdUtils.CreateCommand({
    name: "kakaku",
    description: "kakaku.com を検索します",
    takes: {search: noun_arb_text},
    icon: "http://kakaku.com/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "kakaku.com を検索";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を kakaku.com から検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        var searchUrl = "http://kakaku.com/search_results/?query=" + escape(Utils.convertFromUnicode("Shift-JIS", searchText ) );
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: searchUrl,
          dataType: "html",
          
          
          beforeSend: function(xhr){
            xhr.overrideMimeType("text/html;charset=Shift_JIS");
          },
          
            
          error: function() {
            previewBlock.innerHTML = "Error searching kakaku.com.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var resultBoxes = responseData.find(".resultBox01");
            
            var items = [];
            var count = resultBoxes.length;
            
            count = ( count>=5 ) ? 5 : count;
            
            for (var i = 0; i < count; i++){
                
                var resultBox = jQuery(resultBoxes[i]);
                
                resultBox.find(".details BR").replaceWith(" ");
                
                var item = {
                    imgsrc : resultBox.find(".leftBox img").attr("src"),
                    imgalt : resultBox.find(".leftBox img").attr("alt"),
                    url : resultBox.find(".leftBox a").attr("href"),
                    title : resultBox.find(".title").text(),
                    description : "<b>" + 
                                    resultBox.find(".itemTitleBar + p").text() + "</b>" + 
                                    resultBox.find(".details + div").text() + "<br/>" + 
                                    resultBox.find(".details").text(),
                    key: i+1
                };
                
                items.push(item);
                
            }
            
            var categories = [];
            var ck = 6;
            var seekBoxpes = responseData.find("#More1_pnlMore .seekBody");
            
            seekBoxpes.find(".seekBoxp").each(function(){
                
                var seekBoxp = jQuery(this);
                
                var category = {
                    html : seekBoxp.html(),
                    url : seekBoxp.find("a").attr("href"),
                    key : ck++
                }
                
                categories.push(category);
            });
            
            var previewData = {
                query: searchText,
                items: items,
                categories : categories
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#kakaku", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        var queryText = Utils.convertFromUnicode("Shift-JIS", directObject.text);
        queryText = escape(queryText);
        Utils.openUrlInBrowser( "http://kakaku.com/search_results/" + queryText );
    }
});



CmdUtils.CreateCommand({
    name: "goo-dictionary",
    description: "goo辞書",
    takes: {search: noun_arb_text},
    icon: "http://dictionary.goo.ne.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "<small>goo辞書は無料で使える日本最大級の辞書サービスです。<br/>和英辞典/英和辞典/国語辞典/四字熟語/MBA用語辞典/IT用語辞典/文例集などを提供しています。</small>";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を goo 辞書で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        //Utils.reportInfo(getGooDicUrl(searchText));
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getGooDicUrl(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching Goo Dictionary.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            var items = [];
            var i = 0;
            
            responseData.find("h2.ch04 + .allResultList").each(function(){
                
                var allResultList = jQuery(this);
                
                allResultList.find("A").attr("href", function(){
                    return addBaseUrl(this, "http://ext.dictionary.goo.ne.jp");
                });
                
                var entry = allResultList.find(".entry:first").text();
                var url = allResultList.find(".entry:first a").attr("href");
                var meanings = allResultList.find(".meanings:first").text();
                var dictionary = allResultList.find("DIV:eq(1)").text();
                var dictionaryUrl = allResultList.find("DIV:eq(1) a").attr("href");
                var key = ++i;
                
                var item = {key : key,
                            url : url,
                            meanings : meanings,
                            entry: entry,
                            dictionary : dictionary,
                            dictionaryUrl : dictionaryUrl};
                
                items.push(item);
            });
            
            
            var previewData = {
              query : searchText,
              items : items
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#goodict", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( getGooDicUrl(directObject.text) );
    }
});

function getGooDicUrl(query){
    var url = "http://dictionary.goo.ne.jp/freewordsearcher.html?MT={searchTerms}&IE=UTF-8&OE=UTF-8&kind=all";
    url = url.replace(/%s|{searchTerms}/g, encodeURI(query) );
    return url;
}


CmdUtils.CreateCommand({
    name: "sagawa",
    description: "佐川急便荷物問い合わせ",
    takes: {search: noun_arb_text},
    icon: "http://www.sagawa-exp.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 8) {
            var previewStr = "佐川急便荷物問い合わせ";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> の荷物を問い合わせます...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getSagawaUrl(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error asking Sagawa.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var detail = "";
            responseData.find(".ichiran-fg + .ichiran-fg-msrc2-2").each(function(){ 
                detail = detail + jQuery(this).html() + "<br />" 
            } );
            
            var previewData = {
              query: searchText,
              detail: detail
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#sagawa", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( getSagawaUrl(directObject.text) );
    }
});

function getSagawaUrl(searchText){
    
    var url = "http://k2k.sagawa-exp.co.jp/cgi-bin/mall.mmcgi?{param}";
    var i = 0;
    var req = "";
    var items = searchText.split(" ",10);
    
    for(num in items ){
        //Utils.reportInfo(items[num]);
        var oku = "oku" + parseInt(++i).fillZero(2) + "=" + items[num] + "&";
        req = req + oku;
    }
    //Utils.reportInfo(req);
    url = url.replace(/%s|{param}/g, req );
    return url;

}

CmdUtils.CreateCommand({
    name: "kuronekoyamato",
    description: "ヤマト運輸荷物問い合わせ",
    takes: {search: noun_arb_text},
    icon: "http://www.kuronekoyamato.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 8) {
            var previewStr = "ヤマト運輸荷物問い合わせ";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> の荷物を問い合わせます...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "POST",
          url: "http://toi.kuronekoyamato.co.jp/cgi-bin/tneko",
          data: getKuronekoData(searchText),
          dataType: "html",
          
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            previewBlock.innerHTML = "Error asking Kuronekoyamato.";
          },
          
          success: function(responseData, dataType) {
            
            //responseData = responseData.replace(/(<head>)/ig,'$1<base href="http://toi.kuronekoyamato.co.jp/cgi-bin/tneko">');
            
            responseData = jQuery(responseData);
            
            var detail = '<table style="font-size:85%;" id="detail">';
            responseData.find(".tb_c").each(function(){ 
                var jt = jQuery(this);
                if(jt.find("TD").length < 2){
                    jt.find("TD").attr("colspan",7 - jt.find("TD").length);
                    jt.find("TD").prepend( jQuery.trim( jt.prev().prev().prev().prev().text() )
                                          + "&nbsp;<B>"
                                          + jQuery.trim( jt.prev().prev().prev().text() ) 
                                          + "&nbsp;"
                                          + jQuery.trim( jt.prev().prev().text() )
                                          + "</B>&nbsp;" );
                    jt.find("TD").css({"background":"#666666"});
                }
                detail += jQuery(this).html();
            } );
            detail += "</table>";
            
            detail = jQuery(detail);
            
            detail.find("a").css({color:"white"});
            detail.find("table,td,th").css({"-moz-border-radius":"1px"});
            detail.find("th").attr("bgcolor", "#886633");
            
            detail = detail.outerHTML();
            
            var previewData = {
                query: searchText,
                detail: detail
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#kuronekoyamato", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( "http://toi.kuronekoyamato.co.jp/cgi-bin/tneko", getKuronekoData(directObject.text) );
    }
});

function getKuronekoData(searchText){
    
    var i = 0;
    var req = "";
    var items = searchText.split(" ",10);
    var params = "number00=1&"
    for(num in items ){
        //Utils.reportInfo(items[num]);
        params = params + "number" + parseInt(++i).fillZero(2) + "=" + items[num] + "&";
    }
    //Utils.reportInfo(req);
    return params;

}


CmdUtils.CreateCommand({
    name: "yuupack",
    description: "ゆうパック荷物問い合わせ",
    takes: {search: noun_arb_text},
    icon: "http://www.japanpost.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 11) {
            var previewStr = "ゆうパック、EXPACK、ポスパケット荷物問い合わせ";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> の荷物を問い合わせます...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: 'http://tracking.post.japanpost.jp/service/singleSearch.do?searchKind=S002&locale=ja&reqCodeNo1=' + searchText,
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error asking Yuupack.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            responseData.find("A").each(function()jQuery(this).replaceWith("<div>" + jQuery(this).text() + "</div>"));
            
            var detail = "";
            
            detail = responseData.find(".message_font").text();
            detail = detail + responseData.find(".msg_warning").text();
            
            detail = detail + '<style>th,td{width:auto;height:auto;border:1px solid darkslategray;}</style><table style="width:80%;font-size:80%;background:gray;border:1px solid #dddddd;">';
            
            var res = responseData.find(".search_result").parent().html();
            detail = detail + (res == null ? " " : res);
            
            detail = detail + "</table>";
            
            var previewData = {
              query: searchText,
              detail: detail
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#yuupack", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( 'http://tracking.post.japanpost.jp/service/singleSearch.do?searchKind=S002&locale=ja&reqCodeNo1=' + directObject.text );
    }
});

CmdUtils.CreateCommand({
    name: "kakitome",
    description: "書留記録問い合わせ",
    takes: {search: noun_arb_text},
    icon: "http://www.japanpost.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 11) {
            var previewStr = "一般書留、現金書留、簡易書留、特定記録郵便問い合わせ";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> の書留記録を問い合わせます...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: 'http://tracking.post.japanpost.jp/service/singleSearch.do?searchKind=S001&locale=ja&reqCodeNo1=' + searchText,
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error asking Kakitome.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            responseData.find("A").each(function()jQuery(this).replaceWith("<div>" + jQuery(this).text() + "</div>"));
            
            var detail = "";
            
            detail = responseData.find(".message_font").text();
            detail += responseData.find(".msg_warning").text();
            
            detail += '<style>th,td{width:auto;height:auto;border:1px solid darkslategray;}</style><table style="width:80%;font-size:80%;background:gray;border:1px solid #dddddd;">';
            
            var res = responseData.find(".search_result").parent().html();
            detail += (res == null ? " " : res);
            
            detail += "</table>";
            
            var previewData = {
              query: searchText,
              detail: detail
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#kakitome", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
            Utils.openUrlInBrowser( 'http://tracking.post.japanpost.jp/service/singleSearch.do?searchKind=S001&locale=ja&reqCodeNo1=' + directObject.text );
    }
});


CmdUtils.CreateCommand({
    name: "kotobank",
    description: "Kotobank.jp",
    takes: {search: noun_arb_text},
    icon: "http://kotobank.jp/i/common/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "<small>「kotobank」は、朝日新聞、朝日新聞出版、講談社、小学館などの辞書、事典44冊43万語から、用語を一度に検索できるサービスです。</small>";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を Kotobank で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        //Utils.reportInfo(getGooDicUrl(searchText));
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getKotobankUrl(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching Kotobank Dictionary.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            var items = [];
            var i = 0;
            var baseHref = "http://kotobank.jp";
            
            responseData.find(".wordExpound .wrap .block").each(function(){
                
                var resultList = jQuery(this);
                
                var title = resultList.find(".title").text();
                //var url = ;
                
                resultList.find(".full .doc a").attr("href", function(){
                    return addBaseUrl(this, baseHref);
                });
                var doc = resultList.find(".full .doc").html();
                
                var key = ++i;
                
                var item = {key : key,
                            title : title,
                            doc : doc,
                            };
                
                items.push(item);
                
            });
            
            var previewData = {
              query : searchText,
              items : items
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#kotobank", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( getKotobankUrl(directObject.text) );
    }
});

function getKotobankUrl(query){
    var url = "http://kotobank.jp/search/result?q={searchTerms}&c=opensearch";
    url = url.replace(/%s|{searchTerms}/g, encodeURI(query) );
    return url;
}


CmdUtils.CreateCommand({
    name: "yahoo-news",
    description: "Yahoo news headlines",
    takes: {search: noun_arb_text},
    icon: "http://headlines.yahoo.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "<small>Yahoo! News を検索します</small>";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を Yahoo! news で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: getYahooNewsUrl(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching Yahoo! news.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            var items = [];
            var i = 0;
            
            responseData.find(".searchResult .article + .clearFix").slice(0,5).each(function(){
                
                var resultList = jQuery(this);
                
                var title = resultList.find(".yjMt").html();
                var url = resultList.find(".yjMt").attr("href");
                var description = resultList.find(".yjSt").html();
                var date = resultList.find(".yjSt ~ .date").text();
                var typeImg = "";
                resultList.find(".sqbtSmall").each(function(){
                    typeImg += jQuery(this).outerHTML();
                });
                var photo = resultList.find(".articlePhoto").html();
                
                var key = ++i;
                
                var item = {key : key,
                            title : title,
                            url : url,
                            description : description,
                            date : date,
                            typeImg : typeImg,
                            photo : photo
                            };
                
                items.push(item);
                
            });
            
            var previewData = {
              query : searchText,
              items : items
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#yahoo-news", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( getYahooNewsUrl(directObject.text) );
    }
});

function getYahooNewsUrl(query){
    var url = "http://nsearch.yahoo.co.jp/bin/search?p={searchTerms}";
    url = url.replace(/%s|{searchTerms}/g, encodeURI(query) );
    return url;
}

CmdUtils.CreateCommand({
         
    name: "goo-weather",
    description: "goo天気",
    takes: {"ZIP": noun_arb_text},
    icon: "http://weather.goo.ne.jp/favicon.ico",
    homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
    author: {name: "hokunarin", email: "hokunarin@gmail.com"},
    license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 7) {
            var previewStr = "<small><b>ピンポイント天気検索  − goo 天気</b><br/>7桁の郵便番号を入力します。</small>";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を goo 天気で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        var queryUrl = "http://weather.goo.ne.jp/freewordsearcher.html?MT={QUERY}&id=top";
        queryUrl = queryUrl.replace(/%s|{QUERY}/g, escape(Utils.convertFromUnicode("euc-jp", searchText)));
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: queryUrl,
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching Goo Weather.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var baseHref = "http://weather.goo.ne.jp/";
            
            var title = responseData.find(".ch04:first").text();
            var today = responseData.find(".fs14:first").text();
            
            //Utils.reportInfo(title + today);
            
            /*
            responseData.find("table img").attr("src", function(){
                Utils.reportInfo(this.src);
                return baseHref + this;
            });
            */
            responseData.find("table img").each( function(){
                //Utils.reportInfo(jQuery(this).attr("src"));
                elem = jQuery(this);
                elem.attr("src", baseHref + jQuery(this).attr("src"));
                return elem;
            });
            
            //today
            var todayTable = responseData.find("table.t01:first");
            
            //format
            todayTable.find("table,td,th").css({ "border-spacing":"0px", 
                                                 "border": "1px solid #444466", 
                                                 "border-collaps":"collaps", 
                                                 "font-size":"85%",
                                                 "-moz-border-radius":"2px",
                                                 "background":"#333333",
                                                 "margin":"0px",
                                                 "padding":"0px",
                                                 "width":"90%" });
            todayTable.find("th").css({ "font-size" : "75%",
                                        "background":"#555555"});
            todayTable.find("font[color]").removeAttr("color");
            
            todayTable = todayTable.outerHTML();
            
            //Utils.reportInfo(todayTable);
            
            //tomorrow
            var tomorrowTable = responseData.find("table.t01:eq(1)");
            
            //format
            tomorrowTable.find("table,th,td").css({ "border-spacing":"0px", 
                                                    "border": "1px solid #444466", 
                                                    "border-collaps":"collaps", 
                                                    "font-size":"85%",
                                                    "-moz-border-radius":"2px",
                                                    "background":"#333333",
                                                    "margin":"0px",
                                                    "padding":"0px",
                                                    "width":"90%" });
            tomorrowTable.find("th").css({"font-size" : "75%",
                                            "background":"#555555"});
            tomorrowTable.find("font[color]").removeAttr("color");
            
            tomorrowTable = tomorrowTable.outerHTML();
            
            
            //weekly
            var weeklyTable, weeklyTitle;
            /*
            weeklyTable = responseData.find("table.t03");
            weeklyTable.find("table,th,td").css({ "border-spacing":"0px", 
                                                  "border":"1px solid #444466", 
                                                  "font-size" : "85%",
                                                  "border-collaps" : "collaps"});
            weeklyTable.find("th").css({"font-size" : "75%"});
            weeklyTable = weeklyTable.outerHTML();
            
            weeklyTitle = responseData.find(".ch04:eq(1)").text();
            */
            
            var item = {title : title,
                        today : today,
                        todayTable : todayTable,
                        tomorrowTable : tomorrowTable,
                        weeklyTable : weeklyTable,
                        weeklyTitle : weeklyTitle};
            
            var previewData = {item:item, query:searchText};
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#gooweather", feed.dom).html(),
              previewData);
          },
        
          beforeSend: function(xhr){
            xhr.overrideMimeType("text/html;charset=EUC-JP");
          }
          
        });

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( "http://weather.goo.ne.jp/freewordsearcher.html?MT={QUERY}&id=top".replace(/¥s|{QUERY}/g, escape( Utils.convertFromUnicode("euc-jp", directObject.text) ) ) );
    }
});


CmdUtils.CreateCommand({
    name: "google-news",
    description: "Google news",
    takes: {search: noun_arb_text},
    icon: "http://news.google.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "Google News (news.google.co.jp) を検索します";
            previewBlock.innerHTML = previewStr;
            return;
        }
        
        var previewTemplate = "<b>${query}</b> を Google news で検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: "http://news.google.com/news/search?ned=jp&hl=ja&q=" + encodeURI(searchText),
          dataType: "html",
          
          error: function() {
            previewBlock.innerHTML = "Error searching Google news.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            var items = [];
            var i = 0;
            
            var resultsstats = responseData.find(".results-stats").html();
            
            responseData.find(".headline-story").slice(0,5).each(function(){
                
                var resultList = jQuery(this);
                
                var title = resultList.find(".title").text();
                var url = resultList.find(".title a").attr("href");
                var description = resultList.find(".snippet").html();
                var sourcemedia = resultList.find(".sub-title").text();
                
                var jQphoto = resultList.find(".thumbnail");
                
                jQphoto.find("img").attr( "height", eval(jQphoto.find("img").attr("height")) * 0.6  );
                jQphoto.find("img").attr( "width", eval(jQphoto.find("img").attr("width")) * 0.6  );
                
                jQphoto.find("img").attr( "border", "1");
                
                var photo = jQphoto.html();
                
                var key = ++i;
                
                var item = {key : key,
                            title : title,
                            url : url,
                            description : description,
                            sourcemedia : sourcemedia,
                            photo : photo
                            };
                
                items.push(item);
                
            });
            
            var previewData = {
              query : searchText,
              resultsstats : resultsstats,
              items : items
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#google-news", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( "http://news.google.com/news/search?ned=jp&hl=ja&q=" + encodeURI(directObject.text) );
    }
});


CmdUtils.CreateCommand({
    name: "yahoo-auctions",
    description: "Yahoo! Auctions",
    takes: {search: noun_arb_text},
    icon: "http://auctions.yahoo.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",
    
    preview: function( previewBlock, directObject ) {
        
        var ubiquityVersion = Application.prefs.get("extensions.ubiquity.lastversion").value;
        
        var yahooAppID = "XdZkt_2xg662prW1szQaDNcDSWr8YgQDYMWcQeJ7STR4QQirEK1fGlkUbAgoqKKFZxhA7g--";
        var apiurl = "http://auctions.yahooapis.jp/AuctionWebService/V1/Search";
        
        
        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "Yahoo! Auctions を検索します";
            previewBlock.innerHTML = previewStr;
            return;
        }
        
        var previewTemplate = "<b>${query}</b> を Yahoo! Auctions で検索します...<div id='items'></div>";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        renderItems(0);
        
        function renderItems(pageDiff){
            
            jQuery("#items", previewBlock).replaceWith('<div style="position:absolute;top:40%;left:40%;width:100px;height:50px;" id="progressimage"><img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" /></div>').find("#progressimage").hide().fadeIn(2000);
            
            var page = eval(jQuery("#page" ,previewBlock).text());
            if(page > 0){
                page = page + pageDiff;
            }else{
                page = 1;
            }
            
            var apiPage = Math.floor( ( page - 1 ) * 5 / 50 ) + 1;
            var apiItemIndex = ( (page - 1) * 5 ) - ( apiPage - 1 ) * 50;
            
            CmdUtils.previewAjax(previewBlock, {
                type: "GET",
                url: apiurl,
                data: {appid: yahooAppID, query: searchText, page: apiPage},
                dataType: "xml",
                
                error: function() {
                    previewBlock.innerHTML = "Error searching Yahoo! Auctions.";
                },
                
                success: function(responseData) {
                
                    responseData = jQuery(responseData);
                    var items = [];
                    var i = 0;
                    
                    var resultsnum = responseData.find("AuctionSearchResult").attr("totalAuctions");
                    
                    responseData.find("item").slice(apiItemIndex, apiItemIndex + 5).each(function(){
                        
                        var resultList = jQuery(this);
                        
                        var auctionID = resultList.find("auctionID").text();
                        var title = resultList.find("title").text();
                        var url = resultList.find("url").text();
                        var img = resultList.find("img").text();
                        var price = resultList.find("price").text();
                        var bids = resultList.find("bids").text();
                        var endtime = resultList.find("endtime").text().replace(/ /g,"");
                        var bidorbuy = resultList.find("bidorbuy").text();
                        
                        var seller = [];
                        seller.id = resultList.find("id").text();
                        //seller.itemlist = resultList.find("itemlist").text();
                        seller.itemlist = "http://openuser.auctions.yahoo.co.jp/jp/user/" + seller.id;
                        seller.rating = resultList.find("rating").text();
                        
                        var option = [];
                        resultList.find("option").children().each(function(){
                            option.push(jQuery(this).text());
                        });
                        
                        var key = ++i;
                        
                        var item = {key : key,
                                    auctionID : auctionID,
                                    title : title,
                                    url : url,
                                    img : img,
                                    price : price,
                                    bids : bids,
                                    endtime : endtime,
                                    bidorbuy : bidorbuy,
                                    seller : seller,
                                    option : option
                                    };
                        
                        items.push(item);
                        
                    });
                    
                    
                    var previewData = {
                        query : searchText,
                        resultsnum : resultsnum,
                        items : items,
                        page : page
                    };
                    
                    
                    previewBlock.innerHTML = CmdUtils.renderTemplate(
                        jQuery("#yahoo-auctions", feed.dom).html(),
                        previewData);
                    
                    
                    
                    if(page>1){
                        jQuery("#prev", previewBlock).show();
                        jQuery("#prev", previewBlock).click(function(){
                            renderItems( -1 );
                            jQuery(this).unbind();
                        });
                    }else{
                        jQuery("#prev", previewBlock).hide();
                    }
                    
                    if(resultsnum > page * 5){
                        jQuery("#next", previewBlock).show();
                        jQuery("#next", previewBlock).click(function(){
                            renderItems( 1 );
                            jQuery(this).unbind();
                        });
                    }else{
                        jQuery("#next", previewBlock).hide();
                    }
                    
                    
                    //for Ubiquity 0.1.x / 0.5  difference
                    if (ubiquityVersion.indexOf("0.1.") > -1){
                        jQuery("#prev", previewBlock).attr({href:""});
                        jQuery("#next", previewBlock).attr({href:""});
                    }else{
                        jQuery("#prev", previewBlock).removeAttr("href");
                        jQuery("#next", previewBlock).removeAttr("href");
                    }
                    
                    
                    jQuery(previewBlock).find(".itemview").each( function(){
                        
                        var id = jQuery(this).find(".thumbnail").attr("id");
                        fetchYahooAuctionsItem(this, id);
                        
                    });
                    
                }
            });
        
        
        }

    },

    execute: function( directObject ) {
        Utils.openUrlInBrowser( "http://search.auctions.yahoo.co.jp/jp/search/auc?p=" + escape( Utils.convertFromUnicode("euc-jp", directObject.text) ) );
    }
});

function fetchYahooAuctionsItem(previewBlock, id){
    
    var yahooAppID = "XdZkt_2xg662prW1szQaDNcDSWr8YgQDYMWcQeJ7STR4QQirEK1fGlkUbAgoqKKFZxhA7g--";
    var apiurl = "http://auctions.yahooapis.jp/AuctionWebService/V1/AuctionItem";
    var param = {  appid : yahooAppID, auctionID : id};
    
    
    CmdUtils.previewAjax(previewBlock, { 
        type: "GET",
        url: apiurl,
        data: param,
        datatype: "XML",
        error: function(){
            jQuery(previewBlock).find("div.description").html("<i>failed</i>");
        },
        success: function(responseData) {
            responseData = jQuery(responseData);
            
            var desc = responseData.find("description").text();
            desc = desc.replace( /<[\s\S]*?>/g, "").replace(/\s+/g, " ");
            desc = desc.substring(0, 100) + "...";
            
            var timeleft = responseData.find("timeleft").text();
            
            jQuery(previewBlock).find("span.description").text(desc);
            jQuery(previewBlock).find("span.option").before("残り:" + timeleft + " ");
            
            var imgTemplate = '<img src="${hs}" height="${hh}" />';
            var imgData = {hs:jQuery(previewBlock).find(".thumbnail").attr("imgsrc") , hh:40 };
            
            jQuery(previewBlock).find("div.thumbnail").html(CmdUtils.renderTemplate(imgTemplate, imgData));
            
        }
    });
    
    
}





Number.prototype.fillZero = function(n) {
    return Array((n+1) - this.toString().split('').length).join('0') + this;
}

function addBaseUrl(href, baseUrl){
    
    uri = parseUri(href);
    
    if(uri.host == ""){
        href = baseUrl + href;
    }else if(uri.host == "ubiquity"){
        href = baseUrl + uri.relative;
    }
    
    return href;
}

jQuery.fn.outerHTML = function(s) {
    return (s) ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
}

/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: true,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};


]]></script>
</body>
</html>
